<?php

namespace App\Http\Controllers\Admin\Config\Record;

use Illuminate\Http\Request;
use App\Http\Controllers\AdminController;

use App\Models\Record\Send\Sms;

class SmsController extends AdminController
{
     /**
     * 获取列表数据
     * @return [type] [description]
     */
    function getLists(Request $request){
    	$pageIndex = (int)$request->input('page') ?  $request->input('page') : 1;
    	$length = 10;
    	$start = ($pageIndex-1)*$length;

        $urlPhone   = $request->input('phone');
        $urlTimeArr = $request->input('time');
        $urlStatus  = $request->input('status');
        $urlIsCheck = $request->input('isCheck');

    	$where = [];
        if($urlPhone){
            $where['phone'] = $urlPhone;
        }
        if($urlStatus!=''){
            $where['status'] = $urlStatus;
        }
        if($urlIsCheck!=''){
            $where['isCheck'] = $urlIsCheck;
        }

        $record = Sms::where($where);
        if($urlTimeArr && strtotime($urlTimeArr[0])>0 && strtotime($urlTimeArr[1])>0 && $urlTimeArr[0]>=$urlTimeArr[1]){
            if($urlTimeArr[0]==$urlTimeArr[1]){
                $record = $record->where('created_at','>',$urlTimeArr[0]);
            }else{
                $record = $record->whereBetween('created_at',$urlTimeArr);
            }
        }
    	$data['total'] = $record->count();
    	if($data['total']>0){
    		$data['result'] = $record->orderBy('created_at','desc')->skip($start)->take($length)->get()->toArray();
    	}
    	$this->ajaxJson(0,'',$data);
    }

}
